using FireStarterModeller.BO;
using FireStarterModeller.Test.BO;
using FireStarterModeller.UI;
using Habanero.Faces.Win;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public class TestDMUniqueConstraintAndPropertyEditorControl
    {

        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }


        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();

        }

        [Test]
        public void TestSetBusinessObject()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithUniqueConstraints();
            DMUniqueConstraintAndPropertyEditorControl control =
                new DMUniqueConstraintAndPropertyEditorControl(new ControlFactoryWin());
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            control.Class = dmClass;
            //---------------Test Result -----------------------
            Assert.AreSame(dmClass, control.Class);
            Assert.AreEqual(dmClass.UniqueConstraints.Count, control.UniqueConstraints.Count);
        }

        [Test]
        public void TestDisabledAtCreation()
        {
            //---------------Execute Test ----------------------
            DMUniqueConstraintAndPropertyEditorControl control =
                new DMUniqueConstraintAndPropertyEditorControl(new ControlFactoryWin());
            //---------------Test Result -----------------------

            Assert.IsFalse(control.Enabled);
        }

        [Test]
        public void TestSetEnables()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithProps();
            DMUniqueConstraintAndPropertyEditorControl control =
                new DMUniqueConstraintAndPropertyEditorControl(new ControlFactoryWin());

            //---------------Execute Test ----------------------
            control.Class = dmClass;
            //---------------Test Result -----------------------
            Assert.IsTrue(control.Enabled);
            Assert.IsTrue(control.UniqueConstraintEditorControl.Enabled);
            //Assert.IsTrue(control.DMUniqueConstraintPropertySelectorControl.Enabled);
        }

        [Test]
        public void TestSetToNullDisables()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithProps();
            DMUniqueConstraintAndPropertyEditorControl control =
                new DMUniqueConstraintAndPropertyEditorControl(new ControlFactoryWin());
            control.Class = dmClass;
            //---------------Execute Test ----------------------
            control.Class = null;
            //---------------Test Result -----------------------
            Assert.IsFalse(control.Enabled);
        }

        [Test]
        public void TestSetUniqueConstraint()
        {
            //---------------Set up test pack-------------------
            DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithUniqueConstraints();
            DMUniqueConstraintAndPropertyEditorControl control = new DMUniqueConstraintAndPropertyEditorControl(new ControlFactoryWin());
            control.Class = dmClass;
            DMUniqueConstraint uniqueConstraint = dmClass.UniqueConstraints[0];

            //---------------Execute Test ----------------------
            control.DMUniqueConstraint = uniqueConstraint;

            //---------------Test Result -----------------------
            Assert.AreSame(uniqueConstraint, control.DMUniqueConstraint);
        }

        //[Test]
        //public void TestLinkBetweenUniqueConstraintAndUniqueConstraintPropControls()
        //{
        //    //---------------Set up test pack-------------------
        //    DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithUniqueConstraints();
        //    DMUniqueConstraintAndPropertyEditorControl control = new DMUniqueConstraintAndPropertyEditorControl(new ControlFactoryWin());
        //    control.Class = dmClass;
        //    //---------------Assert Precondition----------------
        //    Assert.AreEqual(2, dmClass.UniqueConstraints.Count);
        //    //---------------Execute Test ----------------------
        //    control.DMUniqueConstraint = dmClass.UniqueConstraints[1];
        //    //---------------Test Result -----------------------
        //    Assert.AreSame(control.DMUniqueConstraint, control.DMUniqueConstraintPropertySelectorControl.BusinessObject);
        //    //---------------Tear Down -------------------------          
        //}

        //[Test]
        //public void Test_SetClass_NoUniqueConstraints_ClearsUniqueConstraintPropControl()
        //{
        //    //--------------- Set up test pack ------------------
        //    DMClass unsavedValidDMClass = TestUtilsShared.CreateUnsavedValidDMClass();
        //    DMClass dmClass = TestUtilsShared.CreateSavedDMClassWithUniqueConstraints();
        //    DMUniqueConstraintAndPropertyEditorControl control = new DMUniqueConstraintAndPropertyEditorControl(new ControlFactoryWin());
        //    control.Class = dmClass;
        //    //--------------- Test Preconditions ----------------
        //    Assert.AreEqual(2, dmClass.UniqueConstraints.Count);
        //    Assert.AreEqual(2, control.DMUniqueConstraintPropertySelectorControl.MultiSelector.AllOptions);
        //    //--------------- Execute Test ----------------------
        //    control.Class = unsavedValidDMClass;
        //    //--------------- Test Result -----------------------
        //    Assert.AreEqual(0, unsavedValidDMClass.UniqueConstraints.Count);
        //    Assert.AreEqual(0, control.DMUniqueConstraintPropertySelectorControl.MultiSelector.AllOptions);

        //}


    }
}